package cn.bld.utils;

import org.apache.commons.io.FilenameUtils;
import org.springframework.web.HttpSessionRequiredException;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class MyFileUtil {
        public static String uploadFile(MultipartFile  uploadFile, String path ) throws IOException {
        String oldName= uploadFile.getOriginalFilename();
        String extName = FilenameUtils.getExtension(oldName);
        String uid = UUID.randomUUID().toString().replace("-","");
        String newName = uid+"."+extName;
        File dir = new File(path);
        if (!dir.exists()){
            dir.mkdir();
        }
        File file = new File(path,newName);
        uploadFile.transferTo(file);
        return newName;
    }

}
